﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HotelManager.Business_Logic_Layer;
using HotelManager.Data_Transfer_Layer;


namespace HotelManager
{
    public partial class NhanPhong : Form
    {
        khachhangBLO kh_blo;
        phongBLO p_blo;
        private string getValue = null;
        private int option = 0;
        private QuanLyPhong qlphong;

        public string truyendulieu
        {
            set { txtPhong.Text = value; }
        }
        public string truyendulieu_tenkh
        {
            set { txtTenkhachhang.Text = value; }
        }

        public NhanPhong()
        {
            InitializeComponent();
            kh_blo = new khachhangBLO();
            p_blo = new phongBLO();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ThemKhachHang frm_themkh = new ThemKhachHang();
            frm_themkh.truyendata_option = 1;
            frm_themkh.Show();
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtTenkhachhang.Text.Length==0)
            {
                MessageBox.Show("Vui lòng nhập tên khách hàng để tìm kiếm", "Lỗi");
                return;
            }
            try
            {
                string tenkh = txtTenkhachhang.Text;
                khachhangDTO obj = new khachhangDTO();
                obj = kh_blo.Find(tenkh);
                if (obj.Kh_id != -1)
                    MessageBox.Show("Co ton tai khach hang");
                else
                    MessageBox.Show("Khong Co ton tai khach hang");
            }
            catch (Exception ex)
            { }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtTenkhachhang.Text.Length == 0 || txtSongaydukien.Text.Length == 0 || txtPhong.Text.Length == 0)
                 {
                MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi");
                return;
            }
            try
            {
                string tenkh = txtTenkhachhang.Text,tenphong=txtPhong.Text,ngayvao=dtpNgayvao.Text,ghichu=txtGhichu.Text,tinhtrang="Đang ở";
                int songaydukien, tratruoc, khuyenmai;
                songaydukien = Convert.ToInt32(txtSongaydukien.Text);
                tratruoc = Convert.ToInt32(txtTratruoc.Text);
                khuyenmai = Convert.ToInt32(txtKhuyenmai.Text);
                if (radDatphong.Checked == true)
                    tinhtrang = "Đã đặt";
                phongDTO p_dto = new phongDTO();
                p_dto = p_blo.View_DetailbyName(tenphong);
                int p_id = p_dto.P_id;
                p_blo.Update_tinhtrang(tinhtrang, p_id);
                //QuanLyPhong uc_qlphong = new QuanLyPhong();
                //uc_qlphong.Refresh();
                QuanLyKhachSan frm = new QuanLyKhachSan();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void txtSongaydukien_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtTratruoc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void txtKhuyenmai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;
            }
        }
    }
}
